import java.util.HashMap;

class DoubleSum {
    public static int[] twoSum(int[] nums, int target) {
        int[] ints = new int[2];
        HashMap<Integer, Integer> map = new HashMap<>(nums.length);
        for (int i = 0; i < nums.length; i++) {
            map.put(nums[i], i);
        }
        for (int i = 0; i < nums.length; i++) {
            if (map.containsKey(target - nums[i]) && i != map.get(target - nums[i])) {
                ints[0] = i;
                ints[1] = map.get(target - nums[i]);
                break;
            }
        }
        return ints;
    }

    public static void main(String[] args) {
        System.out.println(twoSum(new int[]{2,7,11,15}, 9));
    }
}

